#!/usr/bin/python
# -*- coding: utf-8 -*-
#Under the terms of the General Public License v.3
#For more information see LICENSE.txt

#from Element import *
import pygame
from pygame.locals import K_LEFT, K_RIGHT, K_UP, K_DOWN, QUIT, KEYDOWN

class Player (object):


	def __init__(self,map):
		#Element.__init__(self, image, posX, posY)
		self.map = map
		self.image = pygame.image.load('./data/image/nave3.png').convert_alpha()
		self.rect = self.image.get_rect()
		self.rect.move_ip(120, 150)
		self.pointControl_x = 50
		self.pointControl_y = 50


	def updatePosition(self):

		keysPressed = pygame.key.get_pressed()
		dx = 0
		dy = 0

		if keysPressed[K_UP]:
			dy -= 2
		elif keysPressed[K_DOWN]:
			dy = 2
		if keysPressed[K_LEFT]:
			dx -= 2
		elif keysPressed[K_RIGHT]:
			dx = 2


		if not self.map.cantStep(self.rect.x + dx, self.rect.y):
			dx = 0
		if not self.map.cantStep(self.rect.x, self.rect.y + dy):
			dy = 0
		#lineas agregadas por elias
		if not self.map.cantStep(self.rect.x + dx + 12, self.rect.y):
			dx = 0
		if not self.map.cantStep(self.rect.x, self.rect.y + dy + 12):
			dy = 0
				

		self.rect.move_ip(dx, dy)
		self.map.lookAt(self.rect)

	def showPlayer(self, screen):

		x = self.rect.x - self.map.camera_x - self.pointControl_x
		y = self.rect.y - self.map.camera_y - self.pointControl_y
		screen.blit(self.image, (x, y))




